package se.webbzon.oschi01.world;

import java.awt.geom.Point2D;

import se.webbzon.oschi01.nbt.NBTException;
import se.webbzon.oschi01.nbt.Tag;

public class DefaultChunk implements Chunk {
	
	private long timestamp;
	
	private final CoordinateMediator mediator = new CoordinateMediator();
	
	public DefaultChunk(Tag<?> root, long timestamp) {
		if (root == null)
			throw new IllegalArgumentException("The provided root must not be null.");
		
		this.timestamp = timestamp;
		mediator.attachTo(root);
	}

	@Override public Point2D getCoordinate() {
		return mediator.getCoordinate();
	}

	@Override public void setCoordinate(int x, int z) {
		mediator.setCoordinate(x, z);
	}

	@Override public long getTimestamp() {
		return timestamp;
	}

	@Override public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	@Override public Tag<?> getRoot() throws NBTException {
		return mediator.getRoot();
	}
	
	@Override public String toString() {
		Point2D coord = mediator.getCoordinate();
		return "[x=" + coord.getX() + ",z="+ coord.getY() + "]";
	}

	@Override public boolean isLoaded() {
		return true;
	}

	@Override public void free() {};

}
